<template>
  <div>
    <div id="vditor"></div>
    <div class="flex justify-end">
      <a
        href="#"
        class="mt-2 py-2 px-4 bg-gray-700 text-gray-100 rounded-lg hover:bg-gray-900 font-medium"
        >发布</a
      >
    </div>
  </div>
</template>

<script>
/* eslint-disable */

import Vditor from "vditor";
import "../../assets/vditor.css"; // Or use dark

export default {
  mounted() {
    window.vditor = new Vditor("vditor", {
      debugger: true,
      typewriterMode: true,
      placeholder: "placeholder",
      preview: {
        markdown: {
          toc: true,
        },
        hljs: {
          style: "native",
        },
      },
      toolbarConfig: {
        pin: true,
      },
      counter: {
        enable: true,
        type: "text",
      },
      hint: {
        emojiPath:
          "https://cdn.jsdelivr.net/npm/vditor@1.8.3/dist/images/emoji",
        emojiTail:
          '<a href="https://hacpai.com/settings/function" target="_blank">设置常用表情</a>',
        emoji: {
          sd: "💔",
          j: "https://unpkg.com/vditor@1.3.1/dist/images/emoji/j.png",
        },
      },
      tab: "\t",
      upload: {
        accept: "image/*,.mp3, .wav, .rar",
        token: "test",
        url: "/api/upload/editor",
        linkToImgUrl: "/api/upload/fetch",
        filename(name) {
          return name
            .replace(/[^(a-zA-Z0-9\u4e00-\u9fa5\.)]/g, "")
            .replace(/[\?\\/:|<>\*\[\]\(\)\$%\{\}@~]/g, "")
            .replace("/\\s/g", "");
        },
      },
    });
  },
};
</script>
